package Test.FOURTH.Three;

import java.io.File;
import java.io.FileWriter;
import java.util.Scanner;

public class SaveFile {
    File file;
    String filename;
    Scanner sc;

    SaveFile(){
        sc=new Scanner(System.in);
        System.out.print("请输入文件名：");
        String filename=sc.nextLine();
        file=new File(filename+".txt");
    }

    public static void main(String[] args) throws Exception{
        SaveFile saveFile=new SaveFile();
        saveFile.receiveAndWrite();
    }

    public void receiveAndWrite() throws Exception{
        System.out.println("请输入内容");
        String bufferstring;

        FileWriter fileWriter=new FileWriter(file);
        bufferstring=sc.nextLine();
        while (!bufferstring.equals("quit")){
            fileWriter.write(bufferstring);
            fileWriter.flush();
            bufferstring=sc.nextLine();
        }

        fileWriter.flush();
        fileWriter.close();


    }
}
